package com.hukun.ssm1110.controller;

import com.hukun.ssm1110.entity.User;
import com.hukun.ssm1110.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class UserContronller {

    @Autowired
    UserMapper userMapper;

    @RequestMapping("/userList")
    public String userList(Model model) {
        List<User> users = userMapper.getUsers();

        model.addAttribute("users", users);
        return "userList";
    }

    @RequestMapping("/userUpdatePage")
    public String userUpdatePage(Integer userid, Model model) {
        User user = userMapper.getUsersById(userid);
        model.addAttribute("user", user);
        return "userUpdate";
    }


    @RequestMapping("/userUpdate")
    public String userUpdate(User user) {
        int i = userMapper.updateUser(user);
        return "redirect:/userList";
    }


}
